require 'thread_safe'
require 'mutex_m'

module ActiveModel
	class MissingAttributeError < NoMethodError
	end

	module AttributeMethods
		extend ActiveSupport::Concern

		NAME_COMPILABLE_REGEXP = /\a[a-zA-Z_]\w*[!?=]?\z/
		CALL_COMPILABLE_REGEXP = /\a[a-zA-Z_]\w*[!?]?\z/
		
		include do 
			class_attribute :attribute_aliases, :attribute_method_matchers, instance_writer: false 
			self.attribute_aliases = {}
			self.attribute_method_matchers = [ClassMethods::AttributeMethodMatcher.new]
		end

		module ClassMethods
			def attribute_method_prefix(*prefixes)
				self.attribute_method_matchers += prefixes.map! { |prefix| AttributeMethodMatcher.new prefix: prefix}
				undefine_attribute_methods
			end

			def attribute_method_suffix(*suffixes)
				self.attribute_method_matchers += suffixes.map! {|suffix| AttributeMethodMatcher.new suffix: suffix }
				undefine_attribute_methods
			end

			def alias_attribute(new_name, old_name)
				self.attribute_aliases = attribute_aliases.merge(new_name.to_s => old_name.to_s)
				attribute_method_matchers.each do |matcher|
					matcher_new = matcher.method_name(new_name).to_s
					matcher_old = matcher.method_name(old_name).to_s
					define_proxy_call false, self, matcher_new, matcher_old
				end
			end

			
			
		end
			
end
